import requests


# 定义 员工管理 类
class IhrmEmpApi(object):
    # 定义 添加员工 方法
    @classmethod
    def add_emp(cls, header, req_data):
        resp = requests.post(url="https://heimahr-t.itheima.net/api/sys/user",
                             headers=header, json=req_data)
        return resp

    # 定义 查询员工 方法
    @classmethod
    def query_emp(cls, emp_id, header):
        resp = requests.get(url="https://heimahr-t.itheima.net/api/sys/user/" + emp_id, headers=header)
        return resp

    # 定义 修改员工 方法
    @classmethod
    def modify_emp(cls, emp_id, header, req_data):
        resp = requests.put(url="https://heimahr-t.itheima.net/api/sys/user/" + emp_id,
                            headers=header, json=req_data)
        return resp

    # 定义 删除员工 方法
    @classmethod
    def del_emp(cls, emp_id, header):
        return requests.delete(url="https://heimahr-t.itheima.net/api/sys/user/"+emp_id, headers=header)


if __name__ == '__main__':
    req_header = {
        "Authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjEsImlhdCI6MTc0MTE3NzQ3MiwiZXhwIjoxNzQxMTk5MDcyfQ.gn9nxCqI5ChwV-xNdmbvl5JV841EEQVFzAi4Ot5Vmpo"}
    json = {
        "username": "测试张",
        "mobile": "16629914130",
        "workNumber": "",
        "formOfEmployment": 1,
        "departmentId": 3,
        "timeOfEntry": "2025-03-01",
        "correctionTime": "2025-03-05T16:00:00.000Z",
        "staffPhoto": ""
    }
    response = IhrmEmpApi.add_emp(req_header, json)
    print("添加员工结果：", response.json())

    response = IhrmEmpApi.query_emp("4275", req_header)
    print("查询员工结果：", response.json())

    modify_data = {"id": 4275,
                   "mobile": "16629714130",
                   "staffPhoto": "",
                   "username": "测试张",
                   "workNumber": "HEIMA04587",
                   "timeOfEntry": "2025-03-01",
                   "correctionTime": "2025-03-06",
                   "departmentId": 3,
                   "departmentName": "行政部",
                   "formOfEmployment": 1,
                   "roleIds": []}
    response = IhrmEmpApi.modify_emp("4275", req_header, modify_data)
    print("修改员工结果：", response.json())

    response = IhrmEmpApi.del_emp("4275", req_header)
    print("删除员工结果：", response.json())
